package com.ujiuye.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * ClassName: BaseServlet <br/>
 * Description: <br/>
 * date: 2021/9/16 11:05<br/>
 *
 * @author 荒<br />
 * @since JDK 1.8
 */
public class BaseServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        String method = req.getParameter("method");
        Class<? extends BaseServlet> clazz = this.getClass();
        try {
            Method md = clazz.getDeclaredMethod(method,HttpServletRequest.class,HttpServletResponse.class);
            md.setAccessible(true);
            md.invoke(this,req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
